package cn.edu.jmu.oelp.service.impl;

import cn.edu.jmu.oelp.pojo.Entity;
import cn.edu.jmu.oelp.service.EntityNeo4jService;
import cn.edu.jmu.oelp.repository.EntityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EntityNeo4jServiceImpl implements EntityNeo4jService {

    @Autowired
    private EntityRepository entityRepo;

    @Override
    public Entity addEntity(Entity entity) {
        return entityRepo.save(entity);
    }

    @Override
    public void delEntity(Long entityId) {
        Entity entity = entityRepo.findByEntityId(entityId);
        entityRepo.delete(entity);
        System.out.println(entity+"\n删除成功");
    }

    @Override
    public void updateEntity(Entity entity) {
        Entity entity1 = entityRepo.findByEntityId(entity.getEntityId());
        entity1.setEntityId(entity.getEntityId());
        entity1.setArticleId(entity.getArticleId());
        entity1.setParagraphsId(entity.getParagraphsId());
        entity1.setContent(entity.getContent());
        entity1.setType(entity.getType());
//        entity1.setUserId(entity.getUserId());
        System.out.println(entity1);
        entityRepo.save(entity1);
        System.out.println("update完毕");
    }

    @Override
    public List<Entity> findByArticleId(int id) {
        return entityRepo.findByArticleId(id);
    }

    @Override
    public List<Entity> findByArticleIdAndParagraphsId(int articleId, int paraId) {
        return entityRepo.findByArticleIdAndParagraphsId(articleId, paraId);
    }

    @Override
    public List<Entity> findByArticleIdAndParagraphsIdAndUserId(int articleId, int paraId, int userId) {
        return entityRepo.findByArticleIdAndParagraphsIdAndUserId(articleId, paraId, userId);
    }

    @Override
    public Entity findById(long id) {

        return entityRepo.findById(id);
    }

    @Override
    public Entity findByEntityId(long entityId) {
        return entityRepo.findByEntityId(entityId);
    }

    @Override
    public Entity findByContent(String content) {
        return entityRepo.findByContent(content);
    }

    @Override
    public Entity findByArticleIdAndParagraphsIdAndContentAndUserId(int articleId, int paraId, String content, int userId) {
        return entityRepo.findByArticleIdAndParagraphsIdAndContentAndUserId(articleId, paraId, content, userId);
    }

    @Override
    public List<Entity> findByType(String type) {
        return entityRepo.findByType(type);
    }

    @Override
    public List<Entity> findAll() {
        return entityRepo.findAll();
    }
}
